function searchBy() {
    var queryParams = $("#datagrid").datagrid("options").queryParams;
    var entityStatus=document.getElementById('entityStatus');
    if (entityStatus) {
        queryParams.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
    }
    var formData = getFormData(document.getElementById("ff"));
    var params = formData;//transfer(formData);
    for(var i in params){
        queryParams[i] = params[i];
        if(!queryParams[i]){
            delete queryParams[i];
        }
    }
    $("#datagrid").datagrid("reload");
}
function actions(val,row,index){
    var text = row.entityStatus=="OK"?"禁用":"启用";
    return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
        "onclick='edit(\""+row.id+"\")'>修改</a>&nbsp;&nbsp;"+
        "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px' "+
        "onclick='updateStatus(\""+row.id+"\",\""+row.entityStatus+"\")'>"+text+"</a>";
}
function edit(id){
    window.location.href = "./add.html?id="+id;
}

function updateStatus(id,status){
    var message = status=="OK"?"您确定禁用该记录吗？":"您确定启用该记录吗？";
    var module = getModuleName();
    $.messager.confirm("提示",message,function(flag){
        if(flag){
            $.ajax({
                url:config.url+module+"/"+id,
                type:'DELETE',
                xhrFields:{withCredentials:true},
                success:function(data){
                    $.messager.alert("提示","操作成功","info",function () {
                        searchBy();
                    });
                },
                error:function(XMLHttpRequest,textStatus,thrown){
                    $.messager.alert("提示","操作失败","error");
                }
            });
        }
    });
}
$(function () {
   setNav();
   var url = config.url + getModuleName();
   $("#ff").keydown(function (event) {
       var e = event || window.event;
       var keyCode = e.keyCode || e.which;
       if(keyCode=="13"){
           searchBy();
       }
   });
   var initPage = window.initPage||function () {
       var dtd = $.Deferred();
       setTimeout(function () {
           dtd.resolve();
       },500);
       return dtd.promise();
   };
   $.when(initPage()).done(function () {
       var queryParams = getFormData(document.getElementById("ff"));
       queryParams = transfer(queryParams);
       $("#datagrid").datagrid({
           pagination:true,
           rownumbers:true,
           url:url,
           method:'get',
           queryParams:queryParams
       });
   });
});